package org.ezplatform.office.meeting.common.util;

import java.util.HashMap;
import java.util.Map;

import org.ezplatform.mobile.util.message.service.MobileMessageService;
import org.ezplatform.util.RestClient;
import org.ezplatform.util.context.SpringContextHolder;

public class SendMsgThread extends Thread {

	private Map<String, String> msgMap;
	
	private Map<String, Object> messageMap;
	
	private String moduleType;
	
	private String corpId;
	
	private String userIds;
	
	private String orgIds;
	
	private String officeUrlOut;
	
	private String token;
	
	private String type;
	
	private String paramStr;

	public SendMsgThread(String token, String type, String paramStr) {
		super();
		this.token = token;
		this.type = type;
		this.paramStr = paramStr;
	}
	
	public SendMsgThread(String token, String type, Map<String, String> params) {
		super();
		this.token = token;
		this.type = type;
		this.msgMap = params;
	}
	
	public SendMsgThread(Map<String, String> msgTypeMap, Map<String, Object> messageMap, String moduleType,
			String corpId, String userIds, String orgIds, String officeUrlOut, String type) {
		super();
		this.msgMap = msgTypeMap;
		this.messageMap = messageMap;
		this.moduleType = moduleType;
		this.corpId = corpId;
		this.userIds = userIds;
		this.orgIds = orgIds;
		this.officeUrlOut = officeUrlOut;
		this.type = type;
	}

	@Override
	public void run() {
		if("app".equals(type)) {
			MobileMessageService mobileMessageService = SpringContextHolder.getBean("mobileMessageService");
			mobileMessageService.sendMobileMsgThread(corpId, moduleType, userIds, orgIds, msgMap, messageMap, officeUrlOut);
		}else if("pc".equals(type)) {
			RestClient restClient = new RestClient(true);
			restClient.post("/system/umc/message/sendmessage", token, new HashMap<String, String>(), paramStr);
		}else if("email".equals(type)) {
			RestClient restClient = new RestClient(false);
			restClient.get("/mail/modelSendMail", token, msgMap);
		}
	}
	
	
	
}
